package karma.main;

import net.minecraft.client.Minecraft;
import net.minecraft.src.*;

import org.lwjgl.input.Keyboard;

public class ItemHolyLegs extends ItemArmor
{
    static boolean allowblink = true;
    static int counter = 0;
    static int cooldown = 0;
    static int timer = 0;
    static boolean notify = true;
    public static boolean worn = false;
    
	public ItemHolyLegs(int i, EnumArmorMaterial enumarmormaterial, int j, int k)
    {
        super(i, enumarmormaterial, j, k);
    }

    /**
     * Return an item rarity from EnumRarity
     */
    public EnumRarity getRarity(ItemStack itemstack)
    {
        return mod_KarmaCraft.ENCHANTED;
    }
    
    public static void checkIfWorn(Minecraft mc)
    {
        if (mc.thePlayer.inventory.armorInventory[1] != null && mc.thePlayer.inventory.armorInventory[1].getItem() == mod_KarmaCraft.HolyLegs)
        {
            doSpecial(mc);
            worn = true;
            if (!allowblink)
            {
            	cooldown --;
            	if (cooldown == 0)
            	{
            		allowblink = true;
            	}
            }
        }
        else
        {
        	worn = false;
        }
    }
    
    public static void doSpecial(Minecraft mc)
    {
    	EntityPlayer entityplayer = mc.thePlayer;
    	if(counter < 1 && allowblink && Keyboard.isKeyDown(mod_KarmaCraft.key.keyCode))
    	{
    		if(entityplayer.inventory.hasItem(mod_KarmaCraft.MagicPowder.shiftedIndex))
    		{
    			entityplayer.moveFlying(0.0F, 1.0F, 10F);
    			entityplayer.inventory.consumeInventoryItem(mod_KarmaCraft.MagicPowder.shiftedIndex);
    			counter ++;
    		}
    		else
    		{
    			if (notify)
    			{
    				entityplayer.addChatMessage("Not enough Magic Powder to blink!");
    				notify = false;
    				timer = 20;
    			}
    		}
    	}
    	else if (counter == 1)
    	{
    		allowblink = false;
    		counter = 0;
    		cooldown = 100;
    	}
    	
    	if (timer > 0)
    	{
    		timer --;
    		if (timer == 0)
    		{
    			notify = true;
    		}
    	}
    }
}
